import request from "@/utils/request";
import type{SkuInfoData,SkuData,HasSpuResponseData, AllTradeMark,SpuHasImg,SaleAttrResponseData,HasSaleAttrResponseData ,SpuData} from './type'
enum API {
  HAVESPU_URL = '/admin/product/',
  // 获取全部品牌的数据
  ALLTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  //获取某个spu下的已有全部图片
  IMAGE_URL = '/admin/product/spuImageList/',
  //获取某个spu下的已有全部销售属性
  SPUHASSALEATTR_URL = '/admin/product/spuSaleAttrList/',
  //获取整个项目全部的销售属性【颜色，版本，尺码】
  ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',
  //追加一个新的spu
  ADDSPU_URL = '/admin/product/saveSpuInfo',
  //修改已有的spu
  UPDATESPU_URL = '/admin/product/updateSpuInfo',
  //追加一个新增的sku地址
  ADDSKU_URL = '/admin/product/saveSkuInfo',
  //查看某个已有spu下的全部售卖商品（即sku）
  SKU_INFO = '/admin/product/findBySpuId/',
  //删除spu
  REMOVESPU_URL = '/admin/product/deleteSpu/'
}

export const reqHasSpu = (page:number,limit:number,category3Id:string | number) => request.get<any,HasSpuResponseData>(API.HAVESPU_URL+`${page}/${limit}?category3Id=${category3Id}`)
export const reqAllTradeMark = ()=>request.get<any,AllTradeMark>(API.ALLTRADEMARK_URL)

export const reqSpuImageList = (spuId:number)=> request.get<any,SpuHasImg>(API.IMAGE_URL + spuId)

export const reqSpuSaleAttr = (spuId:number)=>request.get<any,SaleAttrResponseData>(API.SPUHASSALEATTR_URL + spuId)

export const reqAllSaleAttr = () => request.get<any,HasSaleAttrResponseData>(API.ALLSALEATTR_URL)
// 添加和修改唯一的区别是 是否有id
// data是新增的spu 或 已有的spu对象
export const reqAddOrUpdateSpu = (data:SpuData) => {
  if(data.id){
    return request.post<any,any>(API.UPDATESPU_URL,data)
  }else{
    return request.post<any,any>(API.ADDSPU_URL,data)
  }
}
//点击保存的时候发这个请求   添加sku请求的方法
export const reqAddSku = (data:SkuData) => request.post<any,any>(API.ADDSKU_URL,data)

 //查看某个已有spu下的全部售卖商品（即sku）  SkuInfoData是请求返回data的数据类型
 export const reqSkuList = (spuId:number|string) => request.get<any,SkuInfoData>(API.SKU_INFO+spuId)

 //删除spu
 export const reqRemoveSpu = (spuId:number|string)=> request.delete<any,any>(API.REMOVESPU_URL+spuId)